<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery-3.3.1.min.js"></script>
</head>

<body>
    <input type="password" id="pwd">
    <p id="msg">请输入6~16位密码</p>
    <script>
        function checkPass() {
            var password = $("#pwd").val();
            var reg_password = /^\w{6,16}$/;
            var flag = reg_password.test(password);
            if (flag) {
                $("#msg").html("可以");
                $("#msg").css("color", "black");
            } else {
                $("#msg").html("请输入6~16位密码");
                $("#msg").css("color", "red");
            }
        }
        $(function() {
            $("#pwd").blur(checkPass);
        });
    </script>
</body>

</html>